<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Vue动态组件</title>
    <script src="./lib/vue-2.4.0.js"></script>
</head>
<body>
    <div id="app">
        <ul>
            <li v-for="(item,key) in navlist"><a @click="go(item.name)" href="javascript:;">{{item.title}}</a></li>
        </ul>

        <component v-bind:is="currNav"></component>
    </div>
</body>
<script>
    var vm=new Vue({
        el:'#app',
        data:{
            navlist:[
                {
                    title:'百度',
                    name:'baidu'
                },
                {
                    title:'谷歌',
                    name:'google'
                },
                {
                    title:'阿里巴巴',
                    name:'ali'
                }
            ],
            currNav:'baidu'
        },
        methods:{
            go:function(name){
                this.currNav=name;
                console.log(name);
            }
        },
        components:{
            baidu:{
                template:'<div>{{title}}</div>',
                data:function(){
                    return {
                        title:'百度'
                    }
                }
            },
            google:{
                template:'<div>{{title}}</div>',
                data:function(){
                    return {
                        title:'谷歌'
                    }
                }
            },
            ali:{
                template:'<div>{{title}}</div>',
                data:function(){
                    return {
                        title:'阿里巴巴'
                    }
                }
            }
        }
    });
</script>
</html>